﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP.Classes;

namespace ERP.View
{
    public partial class viewErp_Thuoctinh : DevExpress.XtraEditors.XtraForm
    {
        public cs_hmr_usersInfo user = new cs_hmr_usersInfo();
        public int flag = 0;
        public int count = 0;
        public cs_erp_hh_thuoctinhInfo hh = new cs_erp_hh_thuoctinhInfo();
        //public cs_hmr_donviInfo dv = new cs_hmr_donviInfo();

        public viewErp_Thuoctinh()
        {
            InitializeComponent();
        }

        private void btnKhongluu_Click(object sender, EventArgs e)
        {
            this.Dispose(true);
        }

        private void viewErp_Thuoctinh_Load(object sender, EventArgs e)
        {
            //this.Load_Data();
            this.CheckUser();
            if (this.flag == 2)
            {
                if (this.hh.Get_Info() > 0)
                {
                    this.Load_Info();
                }
                else
                {
                    this.Dispose(true);
                }
            }
        }

        private void CheckUser()
        {
            cs_hmr_userrightInfo userright = new cs_hmr_userrightInfo();
            userright.groupid = this.user.groupid;
            cs_hmr_winformInfo wf = new cs_hmr_winformInfo();
            wf.tenform = this.Name;
            if (wf.Get_Info() > 0)
            {
                userright.form_id = wf.formid;
                userright.Get_Info();
                if (userright.savedata == 0)
                {
                    this.btnLuu.Enabled = false;
                }
                if (userright.deletedata == 0)
                {
                    //this.btnx
                }
                if (userright.updatedata == 0)
                {
                    this.btnLuu.Enabled = false;
                }
                if (userright.printreport == 0)
                {
                }
            }
        }

        private void Load_Info()
        {
            this.txtTen.Text = this.hh.tenthuoctinh;
            this.txtGhichu.Text = this.hh.ghichu;
        }
        private void Save_Info()
        {
            this.hh.tenthuoctinh = this.txtTen.Text.Trim();
            this.hh.ghichu = this.txtGhichu.Text.Trim();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            this.Save_Info();
            if (this.hh.tenthuoctinh == "")
            {
                MessageBox.Show("Dữ liệu bạn nhập chưa đầy đủ!", "Thông báo...");
                return;
            }
            else
            {
                int i = this.hh.ExcuteProcedure(this.flag);
                if (i > 0)
                {
                    MessageBox.Show("Thực hiện lưu thành công!", "Thông báo...");
                    this.Dispose(true);
                }
                else
                {
                    MessageBox.Show("Không thể lưu thuộc tính, có lỗi!", "Thông báo...");
                }

            }
        }
    }
}